#!/bin/bash

# Function 1
s1_generate_a_series_of_files() {
  for index in {1..100}; do
    filename="/tmp/new_file${index}"
    echo -n "${index}" > "${filename}"
  done
}

# Function 2
s2_list_4_files_in_long_format_about_account_and_group() {
  ls -l /etc | grep -E '(passwd|shadow|group|gshadow)'
}

# Function 3
s3_find_items_related_to_given_username() {
  grep "^$1:" /etc/passwd /etc/shadow | sort
}

# Function 4
s4_find_items_related_to_given_group_name() {
  grep "^$1:" /etc/group /etc/gshadow | sort
}

# Function 5
s5_create_groups_for_given_group_names() {
  for group_name in rnd itoperation; do
    groupadd "${group_name}"
  done
}

# Function 6
s6_create_users_and_set_their_group_as_required() {
  groupadd rnd
  groupadd itoperation

  for user_name in adam bob calvin david edward; do
    useradd -m -G rnd "${user_name}"
  done

  for user_name in calvin david; do
    usermod -aG itoperation "${user_name}"
  done
}

# Function 7
s7_change_users_shell() {
  usermod -s /usr/bin/sh adam
  usermod -s /usr/bin/sh edward
}

# Function 8
s8_set_password_change_policy() {
  for user_name in adam bob calvin david edward; do
    chage -m 10 -M 60 -W 10 "${user_name}"
  done
}

# Function 9
s9_set_password_for_five_users() {
  usernames=("adam" "bob" "calvin" "david" "edward")
  passwords=("$1" "$2" "$3" "$4" "$5")

  for i in "${!usernames[@]}"; do
    echo "${usernames[$i]}:${passwords[$i]}" | chpasswd
  done
}

# Function 10
s10_lock_bobs_password() {
  passwd -l bob
}

# Function 11
s11_include_adam_into_wheel_group() {
  usermod -aG wheel adam
}

# Function 12
s12_change_files_permission() {
  for index in {3..99..3}; do
    filename="/tmp/new_file${index}"
    chmod 620 "${filename}"
  done
}

# Uncomment and call the functions as needed

# s1_generate_a_series_of_files
# s2_list_4_files_in_long_format_about_account_and_group
# s3_find_items_related_to_given_username "username"
# s4_find_items_related_to_given_group_